/**
 * 
 */
package org.yelongframework.model.support.mybatis.mapping.statement;

import java.util.List;
import java.util.Objects;

import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ResultMap;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.session.Configuration;
import org.yelongframework.model.manager.ModelAndTable;
import org.yelongframework.model.support.mybatis.mapping.result.ResultMapBuilder;

/**
 * 映射声明构建器默认实现
 * 
 * @since 1.0.0
 */
public class DefaultMappedStatementBuilder implements MappedStatementBuilder {

	/** 结果映射构建器 */
	private final ResultMapBuilder resultMapBuilder;

	// ==================================================构造器==================================================

	/**
	 * @param resultMapBuilder 结果映射构建器
	 */
	public DefaultMappedStatementBuilder(ResultMapBuilder resultMapBuilder) {
		this.resultMapBuilder = Objects.requireNonNull(resultMapBuilder, "resultMapBuilder");
	}

	// ==================================================构造查询声明==================================================

	@Override
	public MappedStatement buildSelect(String statementId, ModelAndTable modelAndTable, SqlSource sqlSource,
			Configuration configuration) {
		Objects.requireNonNull(statementId);
		MappedStatement.Builder builder = new MappedStatement.Builder(configuration, statementId, sqlSource,
				SqlCommandType.SELECT);
		List<ResultMap> resultMaps = resultMapBuilder.build(modelAndTable, configuration);
		builder.resultMaps(resultMaps);
		return builder.build();
	}

}
